package com.sphd.emanu.activity.send;

import com.google.gson.JsonObject;
import com.sphd.emanu.mvp.BasePresenterImpl;
import com.sphd.emanu.pojo.order.Order;
import com.sphd.emanu.utils.GsonUtil;
import com.wzutils.L;

import java.util.List;

import cn.pedant.SweetAlert.SweetAlertDialog;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class SendPresenter extends BasePresenterImpl<SendContract.View> implements SendContract.Presenter {

    @Override
    public void selectOrderSend(Integer org, int status, int curpage) {
        emanuService.selectOrderSend(org, status, curpage, 10).enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                L.e(response.toString());
                List<Order> orderList = GsonUtil.jsonToList(response.body(),Order.class);
                mView.sendList(orderList);
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {

            }
        });
    }

    @Override
    public void updateOrderStatus(Integer orderId, int status, SweetAlertDialog sweetAlertDialog1) {
        emanuService.updateOrderStatus(orderId, status).enqueue(new Callback<JsonObject>() {
            @Override
            public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                mView.recRes(res(response),sweetAlertDialog1);
            }

            @Override
            public void onFailure(Call<JsonObject> call, Throwable t) {
                Error(t);
            }
        });
    }
}
